package com.powergisol.gis.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.powergisol.gis.entity.TabMarkerColor;
import com.powergisol.gis.entity.TabYc;
import com.powergisol.gis.service.TabDataSettingService;
import com.powergisol.gis.service.TabYcService;
import com.powergisol.gis.util.Result;
import com.powergisol.gis.vo.TabUserVo;
import com.powergisol.gis.vo.YcConditionVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;
import java.util.*;

/**
 * Description:岩层生成相关查询
 */
@RestController
@RequestMapping(value = "yc")
@Api(description = "岩层生成" ,value = "岩层生成")
public class TabYcController extends BaseController{
    @Autowired
    private TabDataSettingService tabDataSettingService;
    @Autowired
    private TabYcService tabYcService;


    @RequestMapping(value = "generateYc", method = RequestMethod.POST)
    @ApiOperation(value = "生成岩层", notes = "生成岩层")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "ycfw", value = "岩层生成范围", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "List<Double[]>", name = "zkfw", value = "钻孔生成岩层的范围", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "Object[]", name = "zkData", value = "钻孔数据", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "String", name = "ycmc", value = "岩层名称", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "String", name = "uuid", value = "生成时唯一标识", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "List<TabMarkerColor>", name = "listColors", value = "岩性颜色设置", defaultValue = "0", required = true, paramType = "query"),
    })
    public Result generateYc(@RequestBody YcConditionVo vo, Principal p){
        TabUserVo userVo =  getUser(p);
        Result r = tabYcService.generateYc(vo,userVo);
        if(r.getCode()==0){
           tabYcService.generateYcNew(vo);
        }
        return r;
    }

    @RequestMapping(value = "upTabYc", method = RequestMethod.POST)
    @ApiOperation(value = "模型生成后返回结果值保存", notes = "岩层生成")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "uuid", value = "uuid", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "String", name = "plane", value = "平面", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "String", name = "wall", value = "墙面", defaultValue = "0", required = true, paramType = "query")
    })
    public Result upTabYc(@RequestBody TabYc tabYc){
        return tabYcService.upTabYc(tabYc.getPlane(),tabYc.getWall(),tabYc.getUuid());
    }

    @RequestMapping(value = "checkYcName", method = RequestMethod.POST)
    @ApiOperation(value = "检查岩层名称是否重复", notes = "检查岩层名称是否重复")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "ycName", value = "ycName", defaultValue = "0", required = true, paramType = "query")
    })
    public Result checkYcName(String ycName){
        return tabYcService.checkYcName(ycName);
    }


    @RequestMapping(value = "getMarkerByUuid", method = RequestMethod.POST)
    @ApiOperation(value = "根据框选范围的uuid获取岩性标识列表", notes = "岩层生成")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "uuid", value = "uuid(多条逗号隔开)", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "String", name = "drillMarker", value = "岩性名称", defaultValue = "0", required = true, paramType = "query")
    })
    public Result getMarkerByUuid(String uuid){
        Result result = new Result();
        List<TabMarkerColor> list = tabDataSettingService.listMarkersByUuid(uuid);
        result.setData(list);
        return result;
    }

    @RequestMapping(value = "getMarkerDetail", method = RequestMethod.POST)
    @ApiOperation(value = "根据岩层的uuid和level获取岩性详情", notes = "根据岩层的uuid和level获取岩性详情")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "uuid", value = "uuid(岩层的uuid)", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "String", name = "zkfc", value = "岩层level", defaultValue = "0", required = true, paramType = "query")
    })
    public Result getMarkerDetail(String uuid,String zkfc){
        Result result = new Result();
        List<TabMarkerColor> list = tabDataSettingService.getMarkerDetail(uuid,zkfc);
        result.setData(list);
        return result;
    }

    @RequestMapping(value = "getYcList", method = RequestMethod.POST)
    @ApiOperation(value = "岩层列表", notes = "岩层列表")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "ycName", value = "岩层名称", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "Integer", name = "state", value = "岩层状态(0生成中1已生成)", defaultValue = "0", required = true, paramType = "query")
    })
    public Result getYcList(@RequestBody TabYc yc,Principal p){
        Result result = new Result();
        yc.setYcUser(null == p ? null: p.getName());
        PageHelper.startPage(yc.getPage(), yc.getLimit());
        PageInfo<TabYc> pageInfo = new PageInfo<>(tabYcService.getYcList(yc));
        result.setCount((int) pageInfo.getTotal());
        result.setData(pageInfo.getList());
        return result;
    }

    @RequestMapping(value = "delYc", method = RequestMethod.POST)
    @ApiOperation(value = "删除岩层", notes = "删除岩层")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "uuid", value = "岩层uuid(多条逗号隔开)", defaultValue = "0", required = true, paramType = "query")
    })
    public Result delYc(String uuid){
        return tabYcService.delYc(uuid);
    }

    @RequestMapping(value = "getYcByUuid", method = RequestMethod.POST)
    @ApiOperation(value = "根据uuid获取岩层", notes = "根据uuid获取岩层")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "uuid", value = "岩层uuid", defaultValue = "0", required = true, paramType = "query")
    })
    public Result getYcByUuid(String uuid){
        return tabYcService.getYcByUuid(uuid);
    }

    @RequestMapping(value = "setYcMarkerColor", method = RequestMethod.POST)
    @ApiOperation(value = "岩层颜色设置", notes = "岩层颜色设置")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "Object[]", name = "zkData", value = "钻孔数据", defaultValue = "0", required = true, paramType = "query")
    })
    public Result setYcMarkerColor(@RequestBody YcConditionVo vo){
        return tabYcService.setYcMarkerColor(vo);
    }
}
